package com.orphan.util.mqConfig;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfing {

    //注入工厂（已经预加载）
    @Autowired
    CachingConnectionFactory connectionFactory;
    //rabbitmq模板
    @Bean(value = "rabbitTemplate")
    public RabbitTemplate rabbitTemplate(){
        return new RabbitTemplate(connectionFactory);
//        RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
//        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());//设置为JSON格式传输对象
//        return rabbitTemplate;
    }

    //注入队列
    @Bean
    //采购单队列
    public Queue queuePurchase(){
        return new Queue("queuePurchase");
    }
    @Bean
    //上架商品队列
    public Queue queueGoosUpShow(){
        return new Queue("queueGoosUpShow");
    }
    @Bean
    //供货商品队列
    public Queue queueSupplier(){
        return new Queue("queueSupplier");
    }
    //退货审核队列
    @Bean
    public Queue queueOrderReturn(){
        return new Queue("queueOrderReturn");
    }
    //供货单成功入库后的队列
    @Bean
    public Queue queueSupplierOut(){
        return new Queue("queueSupplierOut");
    }
    //供应商退货的队列
    @Bean
    public Queue queueSupplierOutTwo(){
        return new Queue("queueSupplierOutTwo");
    }
    //创建队列
    @Bean
    public Queue returnsDetailQueue(){
//        return new Queue("returnsDetailQueue");
        return new Queue("return");
    }


    //创建交换机,默认交换机
    @Bean
    //采购单交换机
    public DirectExchange directPurchaseExchange(){
        return new DirectExchange("purchaseExchange");
    }
    @Bean
    //上架商品交换机
    public DirectExchange directGoodsUpShowExchange(){
        return new DirectExchange("directGoodsUpShowExchange");
    }
    @Bean
    //供货商品交换机
    public DirectExchange directSupplierExchange(){
        return new DirectExchange("directSupplierExchange");
    }
    //退货审核交换机
    @Bean
    public DirectExchange directOrderReturn(){
        return new DirectExchange("directOrderReturn");
    }
    //供货单成功后的交换机
    @Bean
    public DirectExchange directSupplierOut(){
        return new DirectExchange("directSupplierOut");
    }
    //供应商退货的交换机
    @Bean
    public DirectExchange directSupplierOutTwo(){
        return new DirectExchange("directSupplierOutTwo");
    }
    //创建默认交换机
    @Bean
    public DirectExchange frontExchangetest(){
        return new DirectExchange("frontExchangetest");
    }


    //把队列绑定到交换机上
    @Bean
    public Binding queuePurchaseTodirectPurchaseExchange(Queue queuePurchase,DirectExchange directPurchaseExchange){
        return BindingBuilder.bind(queuePurchase).to(directPurchaseExchange).with("purchase");
    }
    @Bean
    public Binding queueGoosUpShowTodirectGoodsUpShowExchange(Queue queueGoosUpShow,DirectExchange directGoodsUpShowExchange){
        return BindingBuilder.bind(queueGoosUpShow).to(directGoodsUpShowExchange).with("goodsUpShow");
    }
    @Bean
    public Binding queueSupplierTodirectSupplierExchange(Queue queueSupplier,DirectExchange directSupplierExchange){
        return BindingBuilder.bind(queueSupplier).to(directSupplierExchange).with("goodsSupplier");
    }
    @Bean
    public Binding queueOrderReturnTodirectOrderReturn(Queue queueOrderReturn,DirectExchange directOrderReturn){
        return BindingBuilder.bind(queueOrderReturn).to(directOrderReturn).with("orderReturn");
    }
    @Bean
    public Binding queueSupplierOutTodirectSupplierOut(Queue queueSupplierOut,DirectExchange directSupplierOut){
        return BindingBuilder.bind(queueSupplierOut).to(directSupplierOut).with("supplierOut");
    }
    @Bean
    public Binding queueSupplierOutTwoTodirectSupplierOutTwo(Queue queueSupplierOutTwo,DirectExchange directSupplierOutTwo){
        return BindingBuilder.bind(queueSupplierOutTwo).to(directSupplierOutTwo).with("supplierOutTwo");
    }
    //把队列绑定到交换机上
    @Bean
    public Binding QueueOneTofrontExchange(Queue returnsDetailQueue, DirectExchange frontExchangetest){
        return BindingBuilder.bind(returnsDetailQueue).to(frontExchangetest).with("returnsDetail");
    }

//  //注入工厂（已经预加载）
//  @Autowired
//  CachingConnectionFactory connectionFactory;
//
//  //rabbitmq模板
//  @Bean(value = "rabbitTemplate")
//  public RabbitTemplate rabbitTemplate() {
//    return new RabbitTemplate(connectionFactory);
//  }
//
//  //注入队列
//  @Bean
//  //采购单队列
//  public Queue queuePurchase() {
//    return new Queue("queuePurchase");
//  }
//
//  @Bean
//  //上架商品队列
//  public Queue queueGoosUpShow() {
//    return new Queue("queueGoosUpShow");
//  }
//
//  @Bean
//  //供货商品队列
//  public Queue queueSupplier() {
//    return new Queue("queueSupplier");
//  }
//
//  @Bean
//  public Queue queueOrderReturn() {
//    return new Queue("queueOrderReturn");
//  }
//
//  //用户队列
//  @Bean
//  public Queue userOne() {
//    return new Queue("queueUser");
//  }
//
//  //创建交换机,默认交换机
//  @Bean
//  //采购单交换机
//  public DirectExchange directPurchaseExchange() {
//    return new DirectExchange("purchaseExchange");
//  }
//
//  @Bean
//  //上架商品交换机
//  public DirectExchange directGoodsUpShowExchange() {
//    return new DirectExchange("directGoodsUpShowExchange");
//  }
//
//  @Bean
//  //供货商品交换机
//  public DirectExchange directSupplierExchange() {
//    return new DirectExchange("directSupplierExchange");
//  }
//
//  @Bean
//  public DirectExchange directOrderReturn() {
//    return new DirectExchange("directOrderReturn");
//  }
//
//  //用户冻结交换机
//  @Bean
//  public DirectExchange queueUsers() {
//    return new DirectExchange("queueUsers");
//  }
//
//  //把队列绑定到交换机上
//  @Bean
//  public Binding queuePurchaseTodirectPurchaseExchange(Queue queuePurchase, DirectExchange directPurchaseExchange) {
//    return BindingBuilder.bind(queuePurchase).to(directPurchaseExchange).with("purchase");
//  }
//
//  @Bean
//  public Binding queueGoosUpShowTodirectGoodsUpShowExchange(Queue queueGoosUpShow, DirectExchange directGoodsUpShowExchange) {
//    return BindingBuilder.bind(queueGoosUpShow).to(directGoodsUpShowExchange).with("goodsUpShow");
//  }
//
//  @Bean
//  public Binding queueSupplierTodirectSupplierExchange(Queue queueSupplier, DirectExchange directSupplierExchange) {
//    return BindingBuilder.bind(queueSupplier).to(directSupplierExchange).with("goodsSupplier");
//  }
//
//  @Bean
//  public Binding queueOrderReturnTodirectOrderReturn(Queue queueOrderReturn, DirectExchange directOrderReturn) {
//    return BindingBuilder.bind(queueOrderReturn).to(directOrderReturn).with("orderReturn");
//  }
//
//  @Bean
//  public Binding QueueToDirectExchangeTwo(Queue userOne,DirectExchange queueUsers){
//    return BindingBuilder.bind(userOne).to(queueUsers).with("queueUsers");
//  }

}
